from Crypto.PublicKey import RSA
rsa_key = RSA.generate(1024)
with open('./private.pem', 'wb') as f:
    private=rsa_key.exportKey()
    f.write(private)

with open('./public.pem', 'wb') as f:
    public = rsa_key.public_key().exportKey()
    f.write(public)
